//起始于1980年


var year = 2019;
var month = 5;
var days = 0;


document.querySelector("#nian").innerHTML = year;
document.querySelector("#yue").innerHTML = month;


//1980年到2019年是闰年还是平年
function runNian(i) {
    if(i % 400 === 0 || (y % 4 === 0 && y % 100 != 0)){
        return true;
    }else {
        return false;
    }
}

//1980年到2019年是闰年天数就是366天否则365天
for(var y = 1980; y < year; y++){
    if (runNian(y)){
        days += 366;
    }else {
        days += 365;
    }
}

//今年1-4月一共过了多少天
for(var m = 1; m < month; m++){
    switch (m){
        case 1:
            days += 31;
            break;
        case 2:
            if(runNian(year)){
                days += 29;
            }else {
                days += 28;
            }
            break;
        case 3:
            days += 31;
            break;
        case 4:
            days += 30;
            break;
        case 5:
            days += 31;
            break;
        case 6:
            days += 30;
            break;
        case 7:
            days += 31;
            break;
        case 8:
            days += 31;
            break;
        case 9:
            days += 30;
            break;
        case 10:
            days += 31;
            break;
        case 11:
            days += 30;
            break;
        case 12:
            days += 30;
            break;
    }
}

//算一下本月有多少天

var day = 0;
switch (month){
    case 1:
        day += 31;
        break;
    case 2:
        if(runNian(year)){
            day += 29;
        }else {
            day += 28;
        }
        break;
    case 3:
        day += 31;
        break;
    case 4:
        day += 30;
        break;
    case 5:
        day += 31;
        break;
    case 6:
        day += 30;
        break;
    case 7:
        day += 31;
        break;
    case 8:
        day += 31;
        break;
    case 9:
        day += 30;
        break;
    case 10:
        day += 31;
        break;
    case 11:
        day += 30;
        break;
    case 12:
        day += 31;
        break;
}

//今年的上个月有多少天

var preday = 0;
if(month = 1){
    preday += 31;
}else {
    switch (month - 1){
        case 1:
            preday += 31;
            break;
        case 2:
            if(runNian(year)){
                preday += 29;
            }else {
                preday += 28;
            }
            break;
        case 3:
            preday += 31;
            break;
        case 4:
            preday += 30;
            break;
        case 5:
            preday += 31;
            break;
        case 6:
            preday += 30;
            break;
        case 7:
            preday += 31;
            break;
        case 8:
            preday += 31;
            break;
        case 9:
            preday += 30;
            break;
        case 10:
            preday += 31;
            break;
        case 11:
            preday += 30;
            break;
        case 12:
            preday += 30;
            break;
    }
}

//因为1980/01/01是从星期二开始的，所以我们从星期日开始算，所以

days +=2;

//算出本月的一号是星期几

var start = days % 7;
console.log(start);

//当前日历一共能放多少天
var num = 42;

//下个月有多少天
var nexdays = num - start -day;



//今天的日期
var thisDate = new Date().getDate();
console.log(thisDate);

document.querySelector("#date1");

//前面的空间
for(var p = preday - start + 1; p <= preday; p++){
    date1.innerHTML += "<span class='num'>"+p+"</span>";
}
for(var t = 1; t <= day; t++){
    if(t == thisDate){
        date1.innerHTML += "<span class='today'>"+t+"</span>";
    }else {
        date1.innerHTML += "<span>"+t+"</span>";
    }
}
for(var z = 1; z <= nexdays; z++){
    date1.innerHTML += "<span class='num'>"+z+"</span>";
}

